package com.jsmy.marketing.activity;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;

import com.jsmy.marketing.R;
import com.jsmy.marketing.adapter.RankListAdapter;
import com.jsmy.marketing.api.RetrofitManager;
import com.jsmy.marketing.base.BaseActivity;
import com.jsmy.marketing.bean.RankListBean;
import com.jsmy.marketing.common.Link;
import com.jsmy.marketing.manager.UserManager;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;

/**
 * 排行榜
 *
 */
public class RankListActivity extends BaseActivity {


    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.refreshLayout)
    SmartRefreshLayout mRefresh;
    @BindView(R.id.my_recycler)
    RecyclerView mRLv;
    RankListAdapter mAdapter;
    List<RankListBean.DataBean.ListBean> mList;
    @Override
    protected int resId() {
        return R.layout.activity_rank_list;
    }

    @Override
    protected void initData() {
        toolbar.setTitle("");
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RankListActivity.this.finish();
            }
        });

        mAdapter = new RankListAdapter();
        mRLv.setLayoutManager(new LinearLayoutManager(this));
        mRLv.setAdapter(mAdapter);
        requestData();
    }

    private void requestData() {
        Map<String, Object> map2 = new HashMap<>();
        map2.put("lid", UserManager.getInstance().getId());
        mPresenter.loadData(RetrofitManager.getInstance().rankList(map2), Link.APP_RANK_LIST);
    }

    @Override
    public void refreshData(Object response, String position) {
        switch (position){
            case Link.APP_RANK_LIST:
                mList = ((RankListBean) response).getData().getList();
                mAdapter.replaceData(mList);
                break;
        }
    }
}
